home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
YERK
/
SUPPLEME
/
UNSUPPOR
/
OPTIONAL
/
PRINT_DR.VR
< prev
next >
Wrap
Text File
|
1986-09-19
|
11KB
|
354 lines
\
\ Printer glue routines
\ See Inside MacIntosh for more information on their use
\
\ NOTE: Because of some bugs in the NEON Assembler some awkward code was used
\ 1: the first 2 lines of PRERROR should be "MOVE.W $0944,D0"
\ but the assembler can not handle absolute addresses
\ 2: Extra NOPs are in some words because branch addresses are calculated
\ wrong when toolbox calls are used in the same word.
\
SCON PRNAME ".Print" \ name of printer driver
\
\ This routine returns the value of the printer error global
\ ( -- error )
:CODE PrError
MOVEA.W #$0944,A0 \ load address of global
MOVE.W (A0),D0 \ get value
EXT.L D0 \ make it NEON full word
MOVE.L D0,-(A7) \ stack it
;CODE
\
\ This routine sets the value of the printer error global
\ ( error -- )
:CODE PrSetError
MOVE.L (A7)+,D0 \ Un-stack value
MOVEA.W #$0944,A0 \ load address of global
MOVE.W D0,(A0) \ set value
;CODE
\
\ this routine is assembler callable only. It opens the printer driver
\
:CODE (PrDrvrOpen)
MOVEQ #24,D0 \ clear a parameter block on the stack
L1 CLR.W -(A7)
DBF D0,L1
MOVE.L NEON[prname],A0 \ get NEON address of SCON
ADD.L #4,A0 \ advance past 1cfa
ADDA.L A3,A0 \ +base
MOVE.L A0,18(A7) \ move into parameter block
MOVE.L A7,A0
Call Open \ open printer driver
ADDA.W #50,A7 \ clear parameter block from stack
MOVEA.W #$0944,A0 \ load address of printer global
MOVE.W D0,(A0) \ set value to returned error code
RTS
;CODE
\
\ the NEON callable routine to open the printer driver
\ ( -- ) result in PrError
:CODE PrDrvrOpen
MOVE.L NEON[(PrDrvrOpen)],D7
JSR 0(A3,D7.l)
;CODE
\
\ Routine to close the printer driver
\ ( -- ) result in PrError
:CODE PrDrvrClose
SUBA.W #50,A7 \ clear a parameter block on the stack
MOVE.L A7,A0
MOVE.W #-3,24(A0) \ move in device number of printer driver
Call Close \ close driver
ADDA.W #50,A7 \ clear parameter block from stack
MOVEA.W #$0944,A0 \ load address of printer global
MOVE.W D0,(A0) \ set value
;CODE
\
\ This routine is assembler callable only.
\ It gets the string resource containing the file name that the CHOOSER
\ has placed in the file SYSTEM. This file is then opened as a resource file.
\ On return, Prerror contains the result code.
\ If PrError = 0 then D0 contains the reference number from OpenResFile.
\ ( -- ) result in PrError
:CODE (PrOpen)
SUBQ #4,A7 \ make room for a handle
MOVE.L #$53545220,-(A7) \ push 'TYPE STRb
MOVE.W #$-2000,-(A7) \ push resource number ($E000) of printer file name
Call GetResource
MOVE.L (A7)+,D0 \ pop resource handle
BEQ ERR \ if NIL, return error in PrError
MOVE.L D0,A1
SUBQ #2,A7 \ make room on stack for result of open
MOVE.L (A1),-(A7) \ push address of string
BSET.B #7,(A1) \ lock string resource
Call OpenResFile \ try to open resource file
MOVE.W (A7)+,D0 \ pop result code
BCLR.B #7,(A1) \ unlock string resource (its purgeable!)
MOVEA.W #2656,A0 \ load address ($0A60) of ResErr global
MOVEA.W #$0944,A1 \ load address of PrintErr global
MOVE.W (A0),(A1) \ copy ResErr to PrintErr
RTS
ERR NOP \ NOPs are to bypass the NEON assembler bug
NOP
MOVEA.W #$0944,A1
MOVE.W #-192,(A1) \ set error into printer global
RTS
;CODE
\
\ This routine opens the printer driver and the print resource file
\ in preparation for printing
\ ( -- ) result in PrError
:CODE PrOpen
MOVE.L NEON[(PrDrvrOpen)],D7
JSR 0(A3,D7.l) \ go open the printer driver
MOVEA.W #$0944,A0
TST.W (A0) \ check if it worked
BNE DONE
MOVE.L NEON[(PrOpen)],D7
JSR 0(A3,D7.l) \ go open the printer resource file
DONE NOP
;CODE
\
\ This routine closes the printer resource file by first opening it
\ just to get the reference number, and then closing it.
\ ( -- ) result in PrError
:CODE PrClose
MOVE.L NEON[(PrOpen)],D7
JSR 0(A3,D7.l) \ go open the printer driver, D0 = file reference
MOVEA.W #$0944,A0 \ load address of PrintErr global
TST.W (A0) \ check it
BNE DONE
MOVE.W D0,-(A7) \ push resource file reference number
Call ClosResFile
MOVEA.W #2656,A0 \ load address ($0A60) of ResErr global
MOVEA.W #$0944,A1 \ load address of PrintErr global
MOVE.W (A0),(A1) \ copy ResErr to PrintErr
DONE NOP
;CODE
\
\ This routine does a control call to the printer driver.
\ See Inside MacIntosh for more information.
\ ( iWhichCtl lParam1 lParam2 lParam3 -- )
:CODE PrCtlCall
MOVE.L (A7)+,A1 \ pop lParam3
MOVE.L (A7)+,D0 \ pop lParam2
MOVE.L (A7)+,D1 \ pop lParam1
MOVE.L (A7)+,D2 \ pop iWhichCtl
SUBA.W #50,A7 \ make parameter block on stack
MOVE.W D2,26(A7) \ move in parameters
MOVE.L D1,28(A7)
MOVE.L D0,32(A7)
MOVE.L A1,36(A7)
MOVE.W #-3,24(A7) \ driver number = -3
MOVE.L A7,A0
Call Control
ADDA.W #50,A7 \ remove parameter block from stack
MOVEA.W #$0944,A0 \ load address of PrintErr global
MOVE.W D0,(A0) \ copy error code to it
;CODE
\
\ This routine is used to call an appropriate printer routine.
\ Printer routines are contained in PDEF resources that are actually
\ code resources with a jump table at the beginning.
\ This routine is called with a variable number of parameters, the PDEF
\ resource number and a control word.
\ The high order 16 bits of the control word contains number of bytes to pop
\ from the stack if the code resource can not be loaded. The high order bit
\ of the next 16 bits is on if the PDEF resource should not be unlocked
\ after it is called. The lowest 8 bits of the control word contain the
\ jump table offset of the appropriate routine to call in the PDEF resource.
\ e.g. 5 $ 00148000 PrintGlue calls PrPicFile
:CODE PrintGlue
MOVE.L A4,-(A6) \ save NEON Instruction Ptr on return stack
MOVE.L (A7)+,D4 \ pop control word
MOVE.L (A7)+,D0 \ pop segment number
SUBQ.L #4,A7 \ make room on stack
MOVE.L #$50444546,-(A7) \ push 'TYPE PDEF
MOVE.W D0,-(A7) \ push resource (i.e. segment) number
Call GetResource \ get printer code segment
MOVE.L (A7)+,D0 \ pop resource handle
BEQ ERR \ if zero, get failed
MOVE.L D0,A4
BSET #7,(A4) \ lock segment
MOVE.L (A4),A0 \ get code segment address
MOVEQ #0,D0
MOVE.B D4,D0
ADDA.L D0,A0 \ calculate jump table address
MOVE.L A0,-(A7)
CLR.B (A7) \ clear high order byte of routine address
MOVE.L (A7)+,A0
JSR (A0) \ call print routine
TST.W D4 \ MSB of word: on implies unlock needed
BPL OUT
BCLR #7,(A4) \ unlock segment
BRA OUT
ERR NOP \ NOP for NEON Assembler branch error
MOVEA.W #$0944,A0 \ load address of PrintErr global
MOVE.W #-192,(A0) \ set error
SWAP D4 \ clean up stack, as GetResource failed
ADDA.W D4,A7
OUT NOP \ NOP for NEON Assembler branch error
MOVE.L (A6)+,A4 \ pop NEON Instruction Ptr from return stack
;CODE
endASM
: (PrintMethod) ( -- code segment number of current printing method )
$ 0946 -base c@ 3 and
;
\ This routine opens the document for printing
\ We will supply the printing grafport, so that it can be a NEON Object
: PrOpenDoc { THPrint -- tpprport }
\ the following moves the low order 3 bits of THPrint.bJDocLoop
\ to printer global $ 0946
\ these bits contain the code segment number that represents
\ the printing method chosen (e.g. draft vs. spool )
$ 0946 -base dup c@ \ get another printer global
$ FC and \ clear lower 3 bits
ptr: THPrint 68 + c@ 3 and \ get masked printing method
or \ or in other bits from printer global
swap c! \ stash it back in global
0 ( for returned port address )
get: THPrint ( the print record )
0 ( we will supply the printing grafport )
0 ( NIL buffer address )
(PrintMethod) $ 000C0000 PrintGlue
;
: PrCloseDoc { TPPrPort -- }
TPPrPort
(PrintMethod) $ 00048004 PrintGlue
;
: PrOpenPage { TPPrPort TPRect -- }
TPPrPort
TPRect 0= IF 0 ELSE abs: TPRect THEN \ page scaling rectangle, if not NIL
(PrintMethod) $ 00040008 PrintGlue
;
: PrClosePage { TPPrPort -- }
TPPrPort
(PrintMethod) $ 0004000C PrintGlue
;
: PrCFGDialog
6 $ 00008000 PrintGlue
;
: PrintDefault { THPrint -- }
get: THPrint 4 $ 00048000 PrintGlue
;
: PrStlDialog { THPrint -- true or false }
word0 get: THPrint
4 $ 00048004 PrintGlue word0 not not
;
: PrJobDialog { THPrint -- true or false }
word0 get: THPrint
4 $ 00048008 PrintGlue word0 not not
;
: PrStlInit { THPrint -- TPPrDlg }
0 get: THPrint
4 $ 0004000C PrintGlue
;
: PrJobInit { THPrint -- TPPrDlg }
0 get: THPrint
4 $ 00040010 PrintGlue
;
: PrDlgMain { THPrint DlgProc -- true or false }
word0 get: THPrint DlgProc
4 $ 00088014 PrintGlue word0 not not
;
: PrValidate { THPrint -- true or false }
word0 get: THPrint
4 $ 00048018 PrintGlue word0 not not
;
: PrJobMerge { THPrint -- true or false }
word0 get: THPrint
4 $ 0008801C PrintGlue word0 not not
;
: PrPicFile { THPrint TPrStatus -- }
get: THPrint
0 ( port address ) 0 ( I/O buffer ) 0 ( device buffer )
abs: TPrStatus ( print status record )
5 $ 00148000 PrintGlue
;
\
\ Printing Status record
\ Methods can be added later
\
:CLASS TPrStatus <super Object
int TotPages \ number of pages in spool file
int CurPage \ page being printed
int TotCopies \ number of copies requested
int CurCopy \ copy being printed
int TotBands
int CurBand
1 bytes PgDirty \ true if started printing page
1 bytes Imaging
handle hPrint \ print record
var pPrPort \ printing grafport
handle hPic
;CLASS
\
\ a test of the printer routines
\
handle hPrint
TPrStatus theStatus
0 value PrPort
rect rtest
: PrintTest
PrOpen
PrError 0=
IF
200 new: hPrint
hPrint PrintDefault
hPrint PrValidate drop
hPrint PrStlDialog drop
hPrint PrJobDialog
IF
pushport
hPrint PrOpenDoc -> PrPort
PrError 0=
IF
PrPort 0 PrOpenPage
PrError 0=
IF
example: rtest 20 10 inset: rtest draw: rtest
THEN
PrPort PrClosePage
THEN
PrPort PrCloseDoc
PrError 0= ptr: hPrint 68 + c@ 1 = and
IF
hPrint theStatus PrPicFile
THEN
popport
THEN
release: hPrint
THEN
PrClose
;